<section class="categories panel rounded">
	<h1>Categories</h1>
	
	<div class="table">
		<div class="thead">
			<div class="th parent"><?php echo lang('heading_parent'); ?></div>
			<div class="th value"><?php echo lang('heading_value'); ?></div>
			<div class="th color"><?php echo lang('heading_color'); ?></div>
			<div class="th actions"><?php echo lang('heading_actions'); ?></div>
			<div class="clear"></div>
		</div>
		<div class="tbody">
			<?php foreach($categories as $category) { ?>
			<form class="row" id="cat_<?php echo $category->id; ?>" method="post" action="api/category/update/<?php echo $category->id; ?>" >
				<div class="td parent">
					<select name="parent_id">
						<option value="null">[none]</option>
						<?php foreach($categories as $cat)
							if ($cat->id != $category->id) {?>
						<option value="<?php echo $cat->id; ?>" <?php if ($cat->id == $category->parent_id) echo ' selected'; ?> style="color: <?php echo '#'.$cat->color; ?>;"><?php echo cat_title($cat,$languages); ?></option>
						<?php } ?>
					</select>
				</div>
				<div class="td value">
					<?php 
						$cat_name_id = 0;
						foreach ($languages as $language) { ?>
						<label for="cat_name_<?php echo $cat_name_id;?>"><?php echo "$language->name: "; ?></label>
						<input id="cat_name_<?php echo $cat_name_id++; ?>" type="text" value="<?php echo $category->{"name_$language->id"}; ?>" name="<?php echo $language->id; ?>"/>
						<br/>
					<?php } ?>
				</div>
				<div class="td color">
					<input type="text" name="color" class="type_color" value="<?php echo $category->color; ?>" style="background-color: <?php echo '#'.$category->color; ?> ;">
				</div>
				<div class="td actions">
					<?php if ($this->user->is_admin()) { ?>
					<a href="api/category/delete/<?php echo $category->id; ?>"><?php echo lang('action_delete'); ?></a>
					<a href="javascript:void(0);" onClick="$('form#cat_<?php echo $category->id; ?>').submit();"><?php echo lang('action_update'); ?></a>
					<?php } ?>
				</div>
				<div class="clear"></div>
			</form>
			<?php } 
			
			if ($this->user->is_admin()) { ?>
			<form class="row new" method="post" action="api/category/insert">
				<div class="td parent">
					<select name="parent_id">
						<option value="null">[none]</option>
						<?php foreach($categories as $cat) { ?>
						<option value="<?php echo $cat->id; ?>"><?php echo cat_title($cat,$languages); ?></option>
						<?php } ?>
					</select>
				</div>
				<div class="td value">
					<?php 
						$cat_name_id = 0;
						foreach ($languages as $language) { ?>
						<label for="cat_name_<?php echo $cat_name_id;?>"><?php echo "$language->name: "; ?></label>
						<input id="cat_name_<?php echo $cat_name_id++; ?>" type="text" name="<?php echo $language->id; ?>"/>
						<br/>
					<?php } ?>
				</div>
				<div class="td color">
					<input type="text" name="color" class="type_color" value="000000" style="background-color: black;">
				</div>
				<div class="td actions">
					<a href="javascript:void(0);" onClick="$('form.new').submit();"><?php echo lang('action_insert'); ?></a>
					
				</div>
				<div class="clear"></div>
			</form>
			<?php } ?>
		</div>		
	</div>
	
</section>

<?php if (!$this->user->is_admin()) { ?>
<script>
	$('input, select').attr('readonly','readonly');
</script>
<?php } ?>
